// ml:run = $bin < input
#include <iostream>
#include <algorithm>

using ll = long long;
ll n, k;

bool judge(ll mid)
{
    auto tn = n;
    auto tk = k;
    tn -= mid + 1;
    tk -= 2;
    auto len = mid / 2;
    return tk * len >= tn;
}

void print_chain(ll first, ll second, ll len)
{
    std::cout << first << " " << second << "\n";
    for (ll i = 1; i < len; i++)
        std::cout << second + i - 1 << " " << second + i << "\n";
}

void print(ll len)
{
    std::cout << len << "\n";
    ll mid = len / 2 + 1;
    n -= k;
    n -= len - 1;
    k -= 2;
    ll now = len + 1;

    print_chain(1, 2, len);
    for (; k > 0; k--) {
        auto tlen = std::min(len / 2, n + 1);
        print_chain(mid, now + 1, tlen);
        now += tlen;
        n -= tlen - 1;
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin >> n >> k;
    auto l = 2;
    auto r = n - 1;
    while (l + 1 < r) {
        auto mid = (l + r) / 2;
        if (judge(mid)) r = mid;
        else l = mid;
    }
    if (judge(l)) r = l;
    print(r);
}

